<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>用数组、for、if 输出最大值和最小值</title>
	</head>

	<body>
		<script>
			/*  第一种
			var arr = [100, 1, 7, 65, 54, 12, 67, 200];
			var min = 0;
			var max = 0;

			function bijiao(m, n) {
				return m - n;
			}
			arr = arr.sort(bijiao);
			console.log(arr);
			console.log(min = arr[0]);
			console.log(max = arr[arr.length - 1]);
			*/
			
			//第二种
			var arr = [100, 1, 7, 65, 54, 12, 67, 200];
			var min = arr[0];
			var max = arr[0];
			for(var i = 0; i < arr.length; i++) {
				if(arr[i] > max) {
					max = arr[i];
				}
				if(arr[i] < min) {
					min = arr[i];
				}
			}

			console.log("最小值" + min);
			console.log("最大值" + max);
		</script>
	</body>

</html>